package com.ding.config;

import java.net.MalformedURLException;
import java.util.Hashtable;

import javax.management.MalformedObjectNameException;
import javax.management.remote.JMXConnector;

import org.springframework.context.annotation.Bean;
import org.springframework.jmx.access.MBeanProxyFactoryBean;
import org.springframework.stereotype.Component;

import com.ding.service.MyService;

@Component
public class JmxConfig {

	@Bean	//MBean代理工厂
	public MBeanProxyFactoryBean myserviceProxyFactoryBean() throws MalformedURLException, MalformedObjectNameException {
		MBeanProxyFactoryBean factoryBean = new MBeanProxyFactoryBean();
		factoryBean.setServiceUrl("service:jmx:rmi:///jndi/rmi://localhost:8888/jmxrmi");
		//远程连接时的账户和密码
		Hashtable<String, String[]> env = new Hashtable<String, String[]>();
		String[] credentials = new String[] {"admain","****"};
		env.put(JMXConnector.CREDENTIALS, credentials);
		factoryBean.setEnvironment(env);
		factoryBean.setObjectName("Test:name=myservice");
		factoryBean.setProxyInterface(MyService.class);
		return factoryBean;
	}
}
